import { Blockchain } from "@rarible/api-client" import type { UnionAddress } from "@rarible/types" import type { MintRequest } from "@rarible/sdk/build/types/nft/mint/mint-request.type" import type { BlockchainWallet } from "@rarible/sdk-wallet" import type { RequestCurrency } from "@rarible/sdk/src/common/domain" import type { OrderRequest } from "@rarible/sdk/src/types/order/common" import type { CreateCollectionRequest } from "@rarible/sdk/src/types/nft/deploy/domain" import { getEthereumWallet, getEthereumWalletBuyer, getWalletAddressFull, } from "../../../common/wallet" import { createSdk } from "../../../common/create-sdk" import { mint } from "../../../common/atoms-tests/mint" import { getCollection } from "../../../common/helpers" import { bid } from "../../../common/atoms-tests/bid" import { getCurrency } from "../../../common/currency" import { cancel } from "../../../common/atoms-tests/cancel" import { createCollection } from "../../../common/atoms-tests/create-collection" function suites(): { blockchain: Blockchain, description: string, isLazy: boolean, wallets: { seller: BlockchainWallet, buyer: BlockchainWallet }, deployRequest: CreateCollectionRequest, mintRequest: (creatorAddress: UnionAddress) => MintRequest, currency: string, bidRequest: (currency: RequestCurrency) => Promise }[] { return [ { blockchain: Blockchain.ETHEREUM, description: "ERC721 <=> ERC20", isLazy: false, wallets: { seller: getEthereumWallet(), buyer: getEthereumWalletBuyer(), }, deployRequest: { blockchain: Blockchain.ETHEREUM, asset: { assetType: "ERC721", arguments: { name: "name", symbol: "RARI", baseURI: "https://ipfs.rarible.com", contractURI: "https://ipfs.rarible.com", isUserToken: false, }, }, } as CreateCollectionRequest, mintRequest: (creatorAddress: UnionAddress): MintRequest => { return { uri: "ipfs://ipfs/QmfVqzkQcKR1vCNqcZkeVVy94684hyLki7QcVzd9rmjuG5", creators: [{ account: creatorAddress, value: 10000, }], royalties: [], lazyMint: false, supply: 1, } }, currency: "ERC20", bidRequest: async (currency: RequestCurrency): Promise => { return { amount: 1, price: "0.0000000000000001", currency: currency, } }, }, { blockchain: Blockchain.ETHEREUM, description: "ERC721_lazy <=> ERC20", isLazy: true, wallets: { seller: getEthereumWallet(), buyer: getEthereumWalletBuyer(), }, deployRequest: { blockchain: Blockchain.ETHEREUM, asset: { assetType: "ERC721", arguments: { name: "name", symbol: "RARI", baseURI: "https://ipfs.rarible.com", contractURI: "https://ipfs.rarible.com", isUserToken: false, }, }, } as CreateCollectionRequest, mintRequest: (creatorAddress: UnionAddress): MintRequest => { return { uri: "ipfs://ipfs/QmfVqzkQcKR1vCNqcZkeVVy94684hyLki7QcVzd9rmjuG5", creators: [{ account: creatorAddress, value: 10000, }], royalties: [], lazyMint: true, supply: 1, } }, currency: "ERC20", bidRequest: async (currency: RequestCurrency): Promise => { return { amount: 1, price: "0.0000000000000001", currency: currency, } }, }, { blockchain: Blockchain.ETHEREUM, description: "ERC1155 <=> ERC20", isLazy: false, wallets: { seller: getEthereumWallet(), buyer: getEthereumWalletBuyer(), }, deployRequest: { blockchain: Blockchain.ETHEREUM, asset: { assetType: "ERC1155", arguments: { name: "name", symbol: "RARI", baseURI: "https://ipfs.rarible.com", contractURI: "https://ipfs.rarible.com", isUserToken: false, }, }, } as CreateCollectionRequest, mintRequest: (creatorAddress: UnionAddress): MintRequest => { return { uri: "ipfs://ipfs/QmfVqzkQcKR1vCNqcZkeVVy94684hyLki7QcVzd9rmjuG5", creators: [{ account: creatorAddress, value: 10000, }], royalties: [], lazyMint: false, supply: 20, } }, currency: "ERC20", bidRequest: async (currency: RequestCurrency): Promise => { return { amount: 5, price: "0.0000000000000001", currency: currency, } }, }, { blockchain: Blockchain.ETHEREUM, description: "ERC1155_lazy <=> ERC20", isLazy: true, wallets: { seller: getEthereumWallet(), buyer: getEthereumWalletBuyer(), }, deployRequest: { blockchain: Blockchain.ETHEREUM, asset: { assetType: "ERC1155", arguments: { name: "name", symbol: "RARI", baseURI: "https://ipfs.rarible.com", contractURI: "https://ipfs.rarible.com", isUserToken: false, }, }, } as CreateCollectionRequest, mintRequest: (creatorAddress: UnionAddress): MintRequest => { return { uri: "ipfs://ipfs/QmfVqzkQcKR1vCNqcZkeVVy94684hyLki7QcVzd9rmjuG5", creators: [{ account: creatorAddress, value: 10000, }], royalties: [], lazyMint: true, supply: 20, } }, currency: "ERC20", bidRequest: async (currency: RequestCurrency): Promise => { return { amount: 5, price: "0.0000000000000001", currency: currency, } }, }, ] } describe.each(suites())("$blockchain mint => floorBid => cancel", (suite) => { const { seller: sellerWallet, buyer: buyerWallet, } = suite.wallets const sellerSdk = createSdk(suite.blockchain, sellerWallet) const buyerSdk = createSdk(suite.blockchain, buyerWallet) test(suite.description, async () => { const walletAddressSeller = await getWalletAddressFull(sellerWallet) const { address } = await createCollection(sellerSdk, sellerWallet, suite.deployRequest) const collection = await getCollection(sellerSdk, address) await mint(sellerSdk, sellerWallet, { collection }, suite.mintRequest(walletAddressSeller.unionAddress)) const requestCurrency = await getCurrency(suite.wallets, suite.currency) const bidRequest = await suite.bidRequest(requestCurrency) const bidOrder = await bid(buyerSdk, buyerWallet, { collectionId: collection.id }, bidRequest) const collection1 = await getCollection(sellerSdk, address) expect(collection1.bestBidOrder?.takePrice).toBe(bidRequest.price) await cancel(buyerSdk, buyerWallet, { orderId: bidOrder.id }) const collection2 = await getCollection(sellerSdk, address) expect(collection2.bestBidOrder).toBe(undefined) }) })