feat: adding sudoswap to sweep (#5257)
* feat: adding sudoswap amm pricing * integrated amm pricing on collection * removing bag recalculation * feat: adding sudoswap to sweep * revisions * typo * adding back recalculating bag * reformatting * simplification * bag recalculation for sudoswap * responding to comments * findindex
This commit is contained in:
parent
8592703931
commit
258be9bf65
@ -249,9 +249,11 @@ export const CollectionNfts = ({ contractAddress, collectionStats, rarityVerifie
|
||||
const [sweepIsOpen, setSweepOpen] = useState(false)
|
||||
// Load all sweep queries. Loading them on the parent allows lazy-loading, but avoids waterfalling requests.
|
||||
const collectionParams = useSweepFetcherParams(contractAddress, 'others', debouncedMinPrice, debouncedMaxPrice)
|
||||
const sudoSwapParams = useSweepFetcherParams(contractAddress, Markets.Sudoswap, debouncedMinPrice, debouncedMaxPrice)
|
||||
const nftxParams = useSweepFetcherParams(contractAddress, Markets.NFTX, debouncedMinPrice, debouncedMaxPrice)
|
||||
const nft20Params = useSweepFetcherParams(contractAddress, Markets.NFT20, debouncedMinPrice, debouncedMaxPrice)
|
||||
useLoadSweepAssetsQuery(collectionParams, sweepIsOpen)
|
||||
useLoadSweepAssetsQuery(sudoSwapParams, sweepIsOpen)
|
||||
useLoadSweepAssetsQuery(nftxParams, sweepIsOpen)
|
||||
useLoadSweepAssetsQuery(nft20Params, sweepIsOpen)
|
||||
|
||||
|
@ -4,8 +4,8 @@ import { BigNumber } from '@ethersproject/bignumber'
|
||||
import { formatEther, parseEther } from '@ethersproject/units'
|
||||
import { SweepFetcherParams, useLazyLoadSweepAssetsQuery } from 'graphql/data/nft/Asset'
|
||||
import { useBag, useCollectionFilters } from 'nft/hooks'
|
||||
import { GenieAsset, Markets } from 'nft/types'
|
||||
import { calcPoolPrice, formatWeiToDecimal } from 'nft/utils'
|
||||
import { GenieAsset, isPooledMarket, Markets } from 'nft/types'
|
||||
import { calcPoolPrice, calcSudoSwapPrice, formatWeiToDecimal, isInSameSudoSwapPool } from 'nft/utils'
|
||||
import { default as Slider } from 'rc-slider'
|
||||
import { useEffect, useMemo, useReducer, useState } from 'react'
|
||||
import styled, { useTheme } from 'styled-components/macro'
|
||||
@ -173,15 +173,17 @@ export const Sweep = ({ contractAddress, minPrice, maxPrice }: SweepProps) => {
|
||||
const markets = useCollectionFilters((state) => state.markets)
|
||||
|
||||
const collectionParams = useSweepFetcherParams(contractAddress, 'others', minPrice, maxPrice)
|
||||
const sudoSwapParams = useSweepFetcherParams(contractAddress, Markets.Sudoswap, minPrice, maxPrice)
|
||||
const nftxParams = useSweepFetcherParams(contractAddress, Markets.NFTX, minPrice, maxPrice)
|
||||
const nft20Params = useSweepFetcherParams(contractAddress, Markets.NFT20, minPrice, maxPrice)
|
||||
// These calls will suspend if the query is not yet loaded.
|
||||
const collectionAssets = useLazyLoadSweepAssetsQuery(collectionParams)
|
||||
const sudoSwapAsssets = useLazyLoadSweepAssetsQuery(sudoSwapParams)
|
||||
const nftxAssets = useLazyLoadSweepAssetsQuery(nftxParams)
|
||||
const nft20Assets = useLazyLoadSweepAssetsQuery(nft20Params)
|
||||
|
||||
const { sortedAssets, sortedAssetsTotalEth } = useMemo(() => {
|
||||
if (!collectionAssets && !nftxAssets && !nft20Assets) {
|
||||
if (!collectionAssets && !sudoSwapAsssets && !nftxAssets && !nft20Assets) {
|
||||
return { sortedAssets: undefined, sortedAssetsTotalEth: BigNumber.from(0) }
|
||||
}
|
||||
|
||||
@ -190,16 +192,31 @@ export const Sweep = ({ contractAddress, minPrice, maxPrice }: SweepProps) => {
|
||||
|
||||
let jointCollections: GenieAsset[] = []
|
||||
|
||||
if (sudoSwapAsssets) jointCollections = [...jointCollections, ...sudoSwapAsssets]
|
||||
if (nftxAssets) jointCollections = [...jointCollections, ...nftxAssets]
|
||||
if (nft20Assets) jointCollections = [...jointCollections, ...nft20Assets]
|
||||
|
||||
const sudoSwapAssetsInJointCollections = jointCollections.filter(
|
||||
(sweepAsset) => sweepAsset.marketplace === Markets.Sudoswap
|
||||
)
|
||||
|
||||
jointCollections.forEach((asset) => {
|
||||
if (!asset.susFlag) {
|
||||
const isNFTX = asset.marketplace === Markets.NFTX
|
||||
const poolPrice = calcPoolPrice(asset, isNFTX ? counterNFTX : counterNFT20)
|
||||
if (BigNumber.from(poolPrice).gt(0)) {
|
||||
isNFTX ? counterNFTX++ : counterNFT20++
|
||||
asset.priceInfo.ETHPrice = poolPrice
|
||||
if (asset.marketplace === Markets.Sudoswap) {
|
||||
const poolPrice = calcSudoSwapPrice(
|
||||
asset,
|
||||
sudoSwapAssetsInJointCollections
|
||||
.filter((sweepAsset) => isInSameSudoSwapPool(asset, sweepAsset))
|
||||
.findIndex((sweepAsset) => sweepAsset.tokenId === asset.tokenId)
|
||||
)
|
||||
asset.priceInfo.ETHPrice = poolPrice ?? ''
|
||||
} else {
|
||||
const isNFTX = asset.marketplace === Markets.NFTX
|
||||
const poolPrice = calcPoolPrice(asset, isNFTX ? counterNFTX : counterNFT20)
|
||||
if (BigNumber.from(poolPrice).gt(0)) {
|
||||
isNFTX ? counterNFTX++ : counterNFT20++
|
||||
asset.priceInfo.ETHPrice = poolPrice
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -216,7 +233,12 @@ export const Sweep = ({ contractAddress, minPrice, maxPrice }: SweepProps) => {
|
||||
|
||||
validAssets = validAssets.slice(
|
||||
0,
|
||||
Math.max(collectionAssets?.length ?? 0, nftxAssets?.length ?? 0, nft20Assets?.length ?? 0)
|
||||
Math.max(
|
||||
collectionAssets?.length ?? 0,
|
||||
sudoSwapAsssets?.length ?? 0,
|
||||
nftxAssets?.length ?? 0,
|
||||
nft20Assets?.length ?? 0
|
||||
)
|
||||
)
|
||||
|
||||
return {
|
||||
@ -226,7 +248,7 @@ export const Sweep = ({ contractAddress, minPrice, maxPrice }: SweepProps) => {
|
||||
BigNumber.from(0)
|
||||
),
|
||||
}
|
||||
}, [collectionAssets, nftxAssets, nft20Assets])
|
||||
}, [collectionAssets, sudoSwapAsssets, nftxAssets, nft20Assets])
|
||||
|
||||
const { sweepItemsInBag, sweepEthPrice } = useMemo(() => {
|
||||
const sweepItemsInBag = itemsInBag
|
||||
@ -411,7 +433,7 @@ const ALL_OTHER_MARKETS = [Markets.Opensea, Markets.X2Y2, Markets.LooksRare]
|
||||
|
||||
export function useSweepFetcherParams(
|
||||
contractAddress: string,
|
||||
market: Markets.NFTX | Markets.NFT20 | 'others',
|
||||
market: Markets.Sudoswap | Markets.NFTX | Markets.NFT20 | 'others',
|
||||
minPrice: string,
|
||||
maxPrice: string
|
||||
): SweepFetcherParams {
|
||||
@ -423,12 +445,23 @@ export function useSweepFetcherParams(
|
||||
return useMemo(() => {
|
||||
if (isMarketFiltered) {
|
||||
if (market === 'others') {
|
||||
return { contractAddress, traits, markets }
|
||||
const marketsToQuery = markets.filter((market) => !isPooledMarket(market as Markets))
|
||||
|
||||
if (marketsToQuery.length > 0) {
|
||||
return {
|
||||
contractAddress,
|
||||
traits,
|
||||
markets: marketsToQuery,
|
||||
}
|
||||
} else {
|
||||
return { contractAddress: '', traits: [], markets: [] }
|
||||
}
|
||||
}
|
||||
return { contractAddress: '', traits: [], markets: [] }
|
||||
if (!markets.includes(market)) return { contractAddress: '', traits: [], markets: [] }
|
||||
}
|
||||
|
||||
switch (market) {
|
||||
case Markets.Sudoswap:
|
||||
case Markets.NFTX:
|
||||
case Markets.NFT20:
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user